package com.internetCafes.spms.web.project.controller;

import com.internetCafes.spms.common.module.excel.ExcelUtils;
import com.internetCafes.spms.common.module.excel.po.ProjectStaticExcel;
import com.internetCafes.spms.common.utils.entity.RR;
import com.internetCafes.spms.common.utils.entity.page.PageItemDTO;
import com.internetCafes.spms.common.utils.entity.page.PageItemVO;
import com.internetCafes.spms.web.project.entity.dto.projectstatistics.ProjectStatisticPagingDTO;
import com.internetCafes.spms.web.project.entity.vo.projectstatistics.ProjectStatisticPagingVO;
import com.internetCafes.spms.web.project.service.IProjectConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = {">>>项目统计"})
@RestController
@RequestMapping("/project/projectStatistics")
public class ProjectStatisticsController {

    @Autowired
    private IProjectConfigService projectConfigService;

    /**
     * 项目统计导出
     */
    @ApiOperation(value = "项目统计导出")
    @PostMapping("/export")
    @RequiresPermissions("project:projectConfig:list")
    public void export(@RequestBody PageItemDTO dto, HttpServletResponse response) {
        List<ProjectStaticExcel> projectStaticExcels = projectConfigService.exportProjectStatic();
        ExcelUtils.exportExcel(projectStaticExcels, "项目统计列表", "项目统计列表", ProjectStaticExcel.class, "项目统计列表.xls", response);
    }

    /**
     * 项目统计列表
     */
    @ApiOperation(value = "项目统计列表")
    @PostMapping("/paging")
    @RequiresPermissions("project:projectStatistics:list")
    public RR<PageItemVO<ProjectStatisticPagingVO>> paging(@RequestBody PageItemDTO<ProjectStatisticPagingDTO> dto) {
        PageItemVO<ProjectStatisticPagingVO> result = projectConfigService.statisticPaging(dto);
        return new RR<>().successData(result);
    }
}
